'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/pages/order/kh/get_order_info 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			out_trade_no
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------

		const order_info = await vk.baseDao.findByWhereJson({
			dbName: "daoju_order",
			whereJson: {
				out_trade_no: out_trade_no,
			}
		})
		
		const { product_list } = order_info
		
		for(let item of product_list){
			console.log('item',item)
			await vk.baseDao.update({
			  dbName: "daoju_merchandise", // 表名
			  whereJson: { // 条件
			    _id: item.merchandise_id,
			  },
			  dataJson: { // 需要修改的数据
			    inventory: _.inc(item.number)
			  }
			});
		}
		
		// console.log('product_list',product_list)
		// return 

		const info = await vk.baseDao.update({
			dbName: "daoju_order",
			whereJson: {
				out_trade_no: out_trade_no,
				user_id: uid
			},
			dataJson: {
				status: -1
			}
		})

		res.data = info

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}